package secret.santa.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiFactory;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DeckPanel;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.Widget;

public class AdminPanel extends Composite 
{

	private static AdminPanelUiBinder uiBinder = GWT
			.create(AdminPanelUiBinder.class);

	interface AdminPanelUiBinder extends UiBinder<Widget, AdminPanel> {
	}
	
	private static final int EVENTS = 0;
	private static final int USERS = 1;
	
	private Secret_Santa santa;

	@UiField
	EventWindow eventPanel;
	@UiField
	UserPanel userPanel;
	@UiField
	MenuBar menu;
	@UiField
	DeckPanel deckPanel;	
	
	@UiFactory EventWindow makeEventWindow() 
	{ 
		return new EventWindow(santa);
	}
	@UiFactory UserPanel makeUserWindow() 
	{ 
		return new UserPanel(santa);
	}

	public AdminPanel(Secret_Santa s)
	{
		santa =s;
		initWidget(uiBinder.createAndBindUi(this));
		makeMenuBar();
		deckPanel.showWidget(USERS);
	}
	private void makeMenuBar() 
	{
		Command signOut;
		Command events;
		Command users;
		events = new Command()
		{
			public void execute() 
			{
				showEvents();
				santa.getUsers();
			}
		};
		users = new Command()
		{
			public void execute() 
			{
				showUsers();
				santa.getUsers();
			}
		};
		signOut = new Command()
		{
			public void execute() 
			{
				santa.signOut();
			}
		};
		
	    menu.addItem("Events", events);
	    menu.addItem("Users", users);
	    menu.addItem("Sign Out", signOut);
		
	}
	protected void showUsers() 
	{
		deckPanel.showWidget(USERS);
		santa.getUsers();
	}
	protected void showEvents() 
	{
		deckPanel.showWidget(EVENTS);
		santa.getEvents();
	}


	public CS_User[] getUserData() 
	{
		return userPanel.getUserData();
	}


	public void displayUsers(CS_User[] u) 
	{
		userPanel.displayUsers(u);	
	}


	public void displayEvents(CS_Event[] e) 
	{
		eventPanel.displayEvents(e);
	}


	public void userEdited() 
	{
		userPanel.userEdited();
	}


	public void eventEdited() 
	{
		eventPanel.eventEdited();
		
	}


	public void userDeleted() 
	{
		userPanel.userDeleted();
	}


	public void eventDeleted() 
	{
		eventPanel.eventDeleted();
	}


	public void displayEventQuery(EventQuery result)
	{
		eventPanel.displayEventQuery(result);
	}


	public void queryForEvent() 
	{
		eventPanel.queryForEvent();
		
	}
}
